<template>
  <div>
    <div style="margin-bottom: 5px" v-if="user.roleId ==0">
      <el-select v-model="cId" filterable placeholder="请选择社团" style="margin-left: 5px;width: 300px" @change="loadPost" >
        <el-option
            v-for="item in cNameData"
            :key="item.cid"
            :label="item.cname"
            :value="item.cid">
        </el-option>
      </el-select>
      <el-button style="margin-left: 5px" type="primary" icon="el-icon-search" @click="loadPost">查询</el-button>
      <el-button style="margin-left: 5px" type="success" icon='el-icon-refresh-left' @click="reset">重置</el-button>
    </div>
    <el-table :data="tableData" style="width: 100%"
              :header-cell-style="{background: '#f3f6fd', color: '#211e1e'}"

    >
      <el-table-column prop="userecordId" label="ID" min-width="40%" align="center">
      </el-table-column>
      <el-table-column prop="usegoodsName" label="领用物品" min-width="100%" align="center">
      </el-table-column>
      <el-table-column prop="useapplyCount" label="领用数量" min-width="60%" align="center">
      </el-table-column>
      <el-table-column prop="userName" label="申请人" min-width="100%" align="center">
      </el-table-column>
      <el-table-column prop="adminName" label="处理人" min-width="100%" align="center">
      </el-table-column>
      <el-table-column prop="cname" label="所属社团" min-width="100%" align="center">
      </el-table-column>
      <el-table-column prop="createtime" label="创建时间" min-width="100%" align="center">
      </el-table-column>
      <el-table-column prop="userecordStatus" label="状态" min-width="100%" align="center">
        <template v-slot="scope">
          <el-tag
              :type="scope.row.userecordStatus === 0 ?'info' :(scope.row.userecordStatus === 1 ?'success' : 'danger')"
              disable-transitions>{{scope.row.userecordStatus === 0 ? '未审批' : (scope.row.userecordStatus === 1 ? '已通过' : '未通过')}}</el-tag>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>

  </div>
</template>
<script>
export default {
  name: "UseapplyManage",
  components: {
  },

  data(){
    return {
      user: JSON.parse(sessionStorage.getItem('CurUser')),
      disabled_index:false,
      tableData: [],
      cNameData:[],
      pageSize:10,
      pageNum:1,
      total:0,
      cId:'',
      centerDialogVisible:false,
    }
  },
  created() {
    // this.loadGet();
    this.loadPost();
    this.loadCname();
  },
  methods:{
    loadCname(){
      this.$axios.get(this.$httpUrl+'/community/list').then(res=>res.data).then(res=>{
        console.log(res)
        if (res.code==200){
          this.cNameData=res.data
          //过滤管理员
          let id = this.cNameData.findIndex(item => {
            if (item.cid == '1') {
              return true
            }
          })
          this.cNameData.splice(id, 1)
        }else{
          alert("获取数据失败")
        }
      })
    },
    resetForm(){
      this.$refs.form.resetFields();
    },
    loadPost(){
      if (this.user.roleId == '0'){
        this.$axios.post(this.$httpUrl+'/userecord/listPage',{
          pageSize:this.pageSize,
          pageNum:this.pageNum,
          params:{
            cId:this.cId+''
          }
        }).then(res=>res.data).then(res=>{
          console.log(res)
          if (res.code==200){
            this.tableData=res.data
            this.total=res.total
          }else{
            alert("获取数据失败")
          }
        })
      }else if(this.user.roleId == '2'){
        this.$axios.post(this.$httpUrl+'/userecord/listPage',{
          pageSize:this.pageSize,
          pageNum:this.pageNum,
          params:{
            cId:this.user.cid+'',
            userId:this.user.userId+''
          }
        }).then(res=>res.data).then(res=>{
          console.log(res)
          if (res.code==200){
            this.tableData=res.data
            this.total=res.total
          }else{
            alert("获取数据失败")
          }
        })
      }else {
        this.$axios.post(this.$httpUrl+'/userecord/listPage',{
          pageSize:this.pageSize,
          pageNum:this.pageNum,
          params:{
            cId:this.user.cid+''
          }
        }).then(res=>res.data).then(res=>{
          console.log(res)
          if (res.code==200){
            this.tableData=res.data
            this.total=res.total
          }else{
            alert("获取数据失败")
          }
        })
      }
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageNum=1
      this.pageSize=val
      this.loadPost()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageNum=val
      this.loadPost()
    },
    reset(){
      this.cId=''
      this.loadPost()
    },

  }
}
</script>

<style scoped>

</style>